import { createRouter, createWebHistory } from 'vue-router'
import { useUserStore } from '../stores/user'
const router = createRouter({
  history: createWebHistory(),
  routes: [
    {
      path: '/',
      redirect: '/seat'
    },
    {
      path: '/seat',
      name: 'seat',
      component: () => import('@/views/seatPage.vue')
    },
    {
      path: '/login',
      name: 'login',
      component: () => import('@/views/loginPage.vue')
    },
    {
      path: '/reservation',
      name: 'reservation',
      component: () => import('@/views/reservationPage.vue')
    }
  ]
})
router.beforeEach((to) => {
  const userStore = useUserStore()
  if (to.path === '/login') {
    return true
  }
  const token = userStore.getToken()
  if (!token) {
    router.push('/login')
    return false
  }
  return true
})
export default router
